<?php

namespace App\Service\Check\KfDataSource;

use App\Enums\Check\CheckEnum;
use App\Library\Rms\RmsPayApi;

class KfRmsPayStream extends BaseKfDataSource
{
    public function generateLists(int $pageNum, int $pageSize): bool
    {
        $data    = (new RmsPayApi(null))
            ->payDetails($this->checkStreamParam->getSysTypes(), $this->checkStreamParam->getStartTime(),
                $this->checkStreamParam->getEndTime(), $pageNum, $pageSize);
        $hasMore = $data['data']['hasMore'] ?? false;

        $this->lists = collect($data['data']['lists'] ?? []);

        return $hasMore;
    }

    public function transfer($item): array
    {
        return [
            'tradeTime'       => $tradeTime = strtotime($item['createdAt']),
            'date'            => (int)date('Ymd', $tradeTime),
            'orderId'         => $item['bizId'],
            'subject'         => $item['subject'],
            'sysType'         => $item['sysType'],
            'tradePrice'      => $item['payPrice'],
            'orderPrice'      => $item['payPrice'],
            'feePrice'        => $item['fee'],
            'feeRate'         => $item['feeRate'],
            'incomePrice'     => $item['payPrice'] - $item['fee'],
            'thirdPayNo'      => $item['thirdPayNo'],
            'company'         => $item['company'],
            'companyAccount'  => $item['companyAccount'],
            'payNo'           => $item['payNo'],
            'payChannel'      => $item['payChannel'],
            'payChannelChild' => $item['payChannelChild'],
            'payAction'       => $item['payAction'],
            'checkStatus'     => CheckEnum::CHECK_STATUS_INIT,
            'errorReason'     => '',
            'remark'          => '',
            'payPic'          => json_encode([]),
        ];
    }
}
